package com.chess.annotation.demo;

import android.graphics.PointF;
import android.view.MotionEvent;

public class MathUtil {

	public static float getZoomDistance(MotionEvent event) {
		float x = event.getX(0) - event.getX(1);
		float y = event.getY(0) - event.getY(1);
		return (float)Math.sqrt(x * x + y * y);
	}

	public static float clamp(final float min, final float value, final float max) {
		return Math.max(min, Math.min(value, max));
	}

	public static float getDistance(float x1, float y1, float x2, float y2) {
		float dx = x1 - x2;
		float dy = y1 - y2;
		return (float)Math.sqrt(dx * dx + dy * dy);
	}

	public static PointF getMidPoint(MotionEvent event) {
		float x = event.getX(0) + event.getX(1);
		float y = event.getY(0) + event.getY(1);
		PointF point = new PointF();
		point.set(x / 2, y / 2);
		return point;
	}
}
